package com.snpic.appaw.module.insure.service.cxImage;

import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import com.snpic.appaw.module.insure.controller.app.cxImage.vo.*;
import com.snpic.appaw.module.insure.dal.dataobject.cxImage.CxImageDO;
import com.snpic.appaw.framework.common.pojo.PageResult;
import com.snpic.appaw.framework.common.util.object.BeanUtils;

import com.snpic.appaw.module.insure.dal.mysql.cxImage.CxImageMapper;

import static com.snpic.appaw.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.snpic.appaw.framework.common.util.collection.CollectionUtils.convertList;
import static com.snpic.appaw.module.insure.enums.ErrorCodeConstants.*;

/**
 * 车险-影像 Service 实现类
 *
 * @author jijun
 */
@Service
@Validated
public class CxImageServiceImpl implements CxImageService {

    @Resource
    private CxImageMapper cxImageMapper;

    @Override
    public Long createCxImageDO(AppCxImageDOSaveReqVO createReqVO) {
        // 插入
        CxImageDO cxImageDO = BeanUtils.toBean(createReqVO, CxImageDO.class);
        cxImageMapper.insert(cxImageDO);

        // 返回
        return cxImageDO.getId();
    }

    @Override
    public void updateCxImageDO(AppCxImageDOSaveReqVO updateReqVO) {
        // 校验存在
        validateCxImageDOExists(updateReqVO.getId());
        // 更新
        CxImageDO updateObj = BeanUtils.toBean(updateReqVO, CxImageDO.class);
        cxImageMapper.updateById(updateObj);
    }

    @Override
    public void deleteCxImageDO(Long id) {
        // 校验存在
        validateCxImageDOExists(id);
        // 删除
        cxImageMapper.deleteById(id);
    }

    @Override
        public void deleteCxImageDOListByIds(List<Long> ids) {
        // 删除
        cxImageMapper.deleteByIds(ids);
        }


    private void validateCxImageDOExists(Long id) {
        if (cxImageMapper.selectById(id) == null) {
            throw exception(CX_IMAGE_DO_NOT_EXISTS);
        }
    }

    @Override
    public CxImageDO getCxImageDO(Long id) {
        return cxImageMapper.selectById(id);
    }

    @Override
    public PageResult<CxImageDO> getCxImageDOPage(AppCxImageDOPageReqVO pageReqVO) {
        return cxImageMapper.selectPage(pageReqVO);
    }

}